<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Chapter 8. Custom Functions</title>
<meta name="generator" content="DocBook XSL Stylesheets V1.75.2">
<link rel="home" href="index.html" title="Smarty 3 Manual">
<link rel="up" href="smarty.for.designers.html" title="Part II. Smarty For Template Designers">
<link rel="prev" href="language.function.while.html" title="{while}">
<link rel="next" href="language.function.cycle.html" title="{cycle}">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<div class="navheader">
<table width="100%" summary="Navigation header">
<tr><th colspan="3" align="center">Chapter 8. Custom Functions</th></tr>
<tr>
<td width="20%" align="left">
<a accesskey="p" href="language.function.while.html">Prev</a> </td>
<th width="60%" align="center">Part II. Smarty For Template Designers</th>
<td width="20%" align="right"> <a accesskey="n" href="language.function.cycle.html">Next</a>
</td>
</tr>
</table>
<hr>
</div>
<div class="chapter" title="Chapter 8. Custom Functions">
<div class="titlepage"><div><div><h2 class="title">
<a name="language.custom.functions"></a>Chapter 8. Custom Functions</h2></div></div></div>
<div class="toc">
<p><b>Table of Contents</b></p>
<dl>
<dt><span class="sect1"><a href="language.custom.functions.html#language.function.counter">{counter}</a></span></dt>
<dt><span class="sect1"><a href="language.function.cycle.html">{cycle}</a></span></dt>
<dt><span class="sect1"><a href="language.function.eval.html">{eval}</a></span></dt>
<dt><span class="sect1"><a href="language.function.fetch.html">{fetch}</a></span></dt>
<dt><span class="sect1"><a href="language.function.html.checkboxes.html">{html_checkboxes}</a></span></dt>
<dt><span class="sect1"><a href="language.function.html.image.html">{html_image}</a></span></dt>
<dt><span class="sect1"><a href="language.function.html.options.html">{html_options}</a></span></dt>
<dt><span class="sect1"><a href="language.function.html.radios.html">{html_radios}</a></span></dt>
<dt><span class="sect1"><a href="language.function.html.select.date.html">{html_select_date}</a></span></dt>
<dt><span class="sect1"><a href="language.function.html.select.time.html">{html_select_time}</a></span></dt>
<dt><span class="sect1"><a href="language.function.html.table.html">{html_table}</a></span></dt>
<dt><span class="sect1"><a href="language.function.mailto.html">{mailto}</a></span></dt>
<dt><span class="sect1"><a href="language.function.math.html">{math}</a></span></dt>
<dt><span class="sect1"><a href="language.function.textformat.html">{textformat}</a></span></dt>
</dl>
</div>
<p>
  Smarty comes with several custom plugin functions that you can
  use in the templates.
 </p>
<div class="sect1" title="{counter}">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="language.function.counter"></a>{counter}</h2></div></div></div>
<p>
   <code class="varname">{counter}</code> is used to print out a count.
   <code class="varname">{counter}</code> will remember the
   count on each iteration. You can adjust the number, the interval
   and the direction of the count, as well as determine whether or not
   to print the value. You can run multiple counters concurrently by
   supplying a unique name for each one. If you do not supply a name,
   the name <span class="quote">“<span class="quote">default</span>”</span> will be used.
  </p>
<p>
   If you supply the <em class="parameter"><code>assign</code></em> attribute, the output of the
   <code class="varname">{counter}</code> function will be assigned to this template
   variable instead of being output to the template.
 </p>
<div class="informaltable"><table border="1">
<colgroup>
<col align="center">
<col align="center">
<col align="center">
<col align="center">
<col>
</colgroup>
<thead><tr>
<th align="center">Attribute Name</th>
<th align="center">Type</th>
<th align="center">Required</th>
<th align="center">Default</th>
<th>Description</th>
</tr></thead>
<tbody>
<tr>
<td align="center">name</td>
<td align="center">string</td>
<td align="center">No</td>
<td align="center"><span class="emphasis"><em>default</em></span></td>
<td>The name of the counter</td>
</tr>
<tr>
<td align="center">start</td>
<td align="center">number</td>
<td align="center">No</td>
<td align="center"><span class="emphasis"><em>1</em></span></td>
<td>The initial number to start counting from</td>
</tr>
<tr>
<td align="center">skip</td>
<td align="center">number</td>
<td align="center">No</td>
<td align="center"><span class="emphasis"><em>1</em></span></td>
<td>The interval to count by</td>
</tr>
<tr>
<td align="center">direction</td>
<td align="center">string</td>
<td align="center">No</td>
<td align="center"><span class="emphasis"><em>up</em></span></td>
<td>The direction to count (up/down)</td>
</tr>
<tr>
<td align="center">print</td>
<td align="center">boolean</td>
<td align="center">No</td>
<td align="center"><span class="emphasis"><em><code class="constant">TRUE</code></em></span></td>
<td>Whether or not to print the value</td>
</tr>
<tr>
<td align="center">assign</td>
<td align="center">string</td>
<td align="center">No</td>
<td align="center"><span class="emphasis"><em>n/a</em></span></td>
<td>the template variable the output will be assigned to</td>
</tr>
</tbody>
</table></div>
<div class="example">
<a name="id393316"></a><p class="title"><b>Example 8.1. {counter}</b></p>
<div class="example-contents">
<pre class="programlisting">

{* initialize the count *}
{counter start=0 skip=2}&lt;br /&gt;
{counter}&lt;br /&gt;
{counter}&lt;br /&gt;
{counter}&lt;br /&gt;

  </pre>
<p>
   this will output:
  </p>
<pre class="screen">

0&lt;br /&gt;
2&lt;br /&gt;
4&lt;br /&gt;
6&lt;br /&gt;

  </pre>
</div>
</div>
<br class="example-break">
</div>
</div>
<div class="navfooter">
<hr>
<table width="100%" summary="Navigation footer">
<tr>
<td width="40%" align="left">
<a accesskey="p" href="language.function.while.html">Prev</a> </td>
<td width="20%" align="center"><a accesskey="u" href="smarty.for.designers.html">Up</a></td>
<td width="40%" align="right"> <a accesskey="n" href="language.function.cycle.html">Next</a>
</td>
</tr>
<tr>
<td width="40%" align="left" valign="top">{while} </td>
<td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td>
<td width="40%" align="right" valign="top"> {cycle}</td>
</tr>
</table>
</div>
</body>
</html>
